from ValueGenerater import ValueGenerater
from QuestionA import QuestionA
import requests
import random


class Question:
    def __init__(self, id, ua=''):
        self.__id = id
        self.__headers = {}
        self.__valueGenerater = ValueGenerater()
        self.__data = None
        if len(ua) == 0:
            self.__ua = '099#KAFEq7EME2QEhGTLEEEEEpEQz0yFZ6VTZXnFA6thSrR7W6V3SrwFG6AcD8ITEEylEcZdQqLWE7EqlGwYrjQXllllqT+dBYFETEEEbORWE7Eqlld3/C4zllllIFrdBYFETEEEbOKZE7EPLEEL/M1ElGii+0v7A3jV1y8D8f82sLZPYM8ItK/nL0JHGRRZz0jVL2Jmef8BVEFETE1EbOKXE7EFEE1Cb/QTEEjtBKlVWEFE5YvGDGTimCXG5c7QBFl59Wf+rZMr80A4rF+tMJ37ZZuGIsT2q7DBI/NrLLFDmStrLLOYB1P0DLOPm/Na35A6cu7vUZVUh7Yss8+So87IwihvyeHoE7EIlllbCeV+MfLrE7EhT3l//oaVsEFEp3llsyaSt3lllllrVliS1qOlluUdt37qn3llWLaStEA4llle33iSwhihE7EUETpCbOaIcL+VJBDtUtxsHsbDSwZnZ0oDrK9u/rikvTY08BQtPoMQ3FMTEEylEcZdt3i5E7EFlllbrBMTE1ZqTcCtU2JlTTuK8fwFtJ4Kryk0Z0Or32ZT+MLS8lX64oBEb/2NNJ86UfkzZ0fZE7Er4ETe/kmNlGgq+0v7A3jV1y8D8f82sLZPYM8ItK/nL0JHGRRZz0jVL2Jmzf8md9UTEEallaxtwEallldIJOAXE7EFEE1Cb/UTEEallG2uHgyllld5hyaWE7EqlldarTqillllpc1duYFEw3llpOUWc/llla+s/hITEEylluZdQ2E='
        else:
            self.__ua = ua

    def __set_header(self):
        self.__headers = {
            'host': 'www.wjx.cn',
            'User-Agent': self.__get_random_ua()
        }

    def __get_random_ua(self):

        # 获取随机UA
        ua = (
            # Opera
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60',
            'Opera/8.0 (Windows NT 5.1; U; en)',
            'Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50',
            'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.50',

            # Firefox
            'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
            'Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10',

            # Safari
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2',

            # chrome
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36',
            'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
            'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16',

            # 360
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36',
            'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',

            # 淘宝浏览器
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11',

            # 猎豹浏览器
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER',
            'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)',
            'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)"',

            # QQ浏览器
            'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)',
            'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)',

            # sogou浏览器
            'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0',
            'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)',

            # maxthon浏览器
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.3.4000 Chrome/30.0.1599.101 Safari/537.36',

            # UC浏览器
            'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 UBrowser/4.0.3214.0 Safari/537.36'
        )

        return ua[random.randint(0, len(ua)-1)]

    def __get_source(self):
        self.__source = requests.get(
            'https://www.wjx.cn/jq/%d.aspx' % self.__id, headers=self.__headers).text

    def exe(self, num):
        self.__set_header()
        self.__get_source()
        self.__data = self.__valueGenerater.exec(self.__source)

        questionA = QuestionA(self.__id, self.__source, )
        questionA.mul_run(self.__data, num)
